package javamusic.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import javamusic.excepcion.DAOExcepcion;
import javamusic.modelo.Boleta;
import javamusic.util.ConexionBDKaraoke;

public class BoletaDAO extends BaseDAO{

	public Collection<Boleta> buscarnumeroboleta(int idcomprobante) throws DAOExcepcion {
		String query = "select numeroboleta, idcomprobante from boleta where idcomprobante like ?";
		Collection<Boleta> lista = new ArrayList<Boleta>();
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			con = ConexionBDKaraoke.obtenerConexion();
			stmt = con.prepareStatement(query);
			stmt.setString(1, "%" + idcomprobante + "%");
			rs = stmt.executeQuery();
			while (rs.next()) {
				Boleta vo = new Boleta();
				vo.setNumeroboleta(rs.getString("numeroboleta"));
				vo.setIdcomprobante(rs.getInt("idcomprobante"));
				lista.add(vo);
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarResultSet(rs);
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
						
		return lista;
	}
	
}
